package cn.wenhaha.common.utils;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 分页类型转换
 * --------
 *
 * @author ：wyndem
 * @Date ：Created in 2022-10-08 19:37
 */
public class PageConvert {

    public  static <T,K extends Model>  Page<T>  convertPage(Page<K> page, Function<? super K,T> mapper){
        List<K> list = page.getList();
        List<T> collect = list.stream().map(mapper).collect(Collectors.toList());
       return new Page<T>(collect,page.getPageNumber(),page.getPageSize(),page.getTotalPage(),page.getTotalRow());
    }

}
